package com.oracle.violet.first.until

import org.apache.spark.sql.Row

object CaculateUntils {

  def sourceData(row: Row)= {
    //提取相应字段
    val reqmode = row.getAs[Int]("requestmode")
    val pronode = row.getAs[Int]("processnode")
    val iseffect = row.getAs[Int]("iseffective")
    val isbiling = row.getAs[Int]("isbilling")
    val isbid = row.getAs[Int]("isbid")
    val iswin = row.getAs[Int]("iswin")
    val adorderid = row.getAs[Int]("adorderid")


    val adRawReq = if (reqmode == 1 && pronode >= 1) 1 else 0
    val adEffReq = if (reqmode == 1 && pronode >= 2) 1 else 0
    val adReq = if (reqmode == 1 && pronode == 3) 1 else 0

    val adRtbsReq = if (iseffect == 1 && isbiling == 1 && isbid == 1 && adorderid != 0) 1 else 0
    val adRtbReq = if (iseffect == 1 && isbiling == 1 && iswin == 1) {
      val winprice = row.getAs[Double]("winprice")
      val adpayment = row.getAs[Double]("adpayment")
      (1, winprice / 1000, adpayment / 1000)
    } else (0, 0d, 0d)
    val adshow = if (reqmode == 2 && iseffect == 1) 1 else 0
    val adClick = if (reqmode == 3 && iseffect == 1) 1 else 0

    List(adRawReq,adEffReq,adReq,adRtbsReq,adRtbReq._1,adshow,adClick,adRtbReq._2,adRtbReq._3)
  }


}
